package com.mvc.service.healthmanager.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.mvc.dao.BaseDaoI;
import com.mvc.dao.mapper.BodycheckDao;
import com.mvc.model.base.SugarFollowCheckResultData;
import com.mvc.model.base.bodyCheck.AuxiliaryFunction;
import com.mvc.model.base.bodyCheck.BodyCheckData;
import com.mvc.model.healthmanager.archive.BloodSugar;
import com.mvc.model.healthmanager.archive.BloodSugarStandardization;
import com.mvc.model.healthmanager.archive.BodyCheck;
import com.mvc.model.mb.archive.BaseInfo;
import com.mvc.service.healthmanager.BodyCheckServiceI;
import com.mvc.service.mb.BaseInfoServiceI;
import com.mvc.utils.StringUtil;
import com.mvc.utils.ValidatorUtil;

@Service
public class BodyCheckServiceImpl implements BodyCheckServiceI{
	@Autowired
	private BaseDaoI<BodyCheck> bDaoI;
	@Autowired
	private BaseInfoServiceI bsi;

	@Override
	public List<BodyCheck> findBodyChecks(BodyCheck bc) {
		Map<String, Object> params = StringUtil.beanToMap(bc);
		return bDaoI.find(StringUtil.getHql("BodyCheck", params, "asc"), params);
	}

	@Override
	public List<BodyCheck> findBodyChecks(BaseInfo bi) {
		List<BaseInfo> list = bsi.findBaseInfos(bi);
		List<BodyCheck> li = new ArrayList<BodyCheck>();
		for(BaseInfo b:list){
			List<BodyCheck> l = bDaoI.find("from BodyCheck b where b.personId = '"+b.getPersonId()+"' order by b.id desc");
			if(l.size()>0){
				BodyCheck bc = l.get(0);
				li.add(bc);
			}
		}
		return li;
	}

}
